﻿using MediatR;
using WMS.API.Application.Command.DeliveryOrderManagement.DeliveryOrder;
using WMS.API.Application.Command.StocktakingManagement.PendingOrder;
using WMS.Domain.Entities.DeliveryOrderManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.DeliveryOrderManagement.DeliveryOrder
{
    /// <summary>
    /// 删除
    /// </summary>
    public class DeletePendingFreightCommandHandler : IRequestHandler<DeletePendingFreightCommand, APIResult<int>>
    {
        private readonly IBaseRepository<PendingFreightModel> _pendingrepository;

        public DeletePendingFreightCommandHandler(IBaseRepository<PendingFreightModel> pendingrepository)
        {
            this._pendingrepository = pendingrepository;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<int>> Handle(DeletePendingFreightCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>("删除成功待发货订单");
            result.Message = "删除成功待发货订单";
            result.Code=ResultCode.Success;

            await _pendingrepository.DeleteAsync(request.Id);
            return await Task.FromResult(result);
        }
    }
}
